Templates
These are the core for bootstrapping new projects. The default templates can be found in this repo in src/templates/[type]. You can however define you own template, by providing a custom path:
plz create my-project --template=../../path/to/template
# ^ path is relative to current working directory!
Use github repos as templates
If you have a public repository on github that contains the template you want to use, you can simply use the url of that repo in plz create.
plz create my-app --template=git@github.com:your-username/your-template.git
Plz will clone the repo into a temporary folder, copy the files, parse the template (see below) and remove the temporary folder again. If your template is in a subdirectory of a repo, simply add the path relative to the repo root to that url.
plz create my-app --template=git@github.com:your-username/your-template.git/some path
Use npm packages as templates
The easiest way to use npm packages as templates is to use the "relative path" option to specify them. Simply install the template package globally and then reference it from the npm root directory.
npm i -g your-template-package
plz create my-app --template="$(npm root -g)/your-template-package"
Use global plz config to override default templates
If you always want to use specific templates instead of plz's defaults, you can override the plz config via the config command.
plz config templates.react-app ./path/to/template
plz config templates.react-component ./another/path
This supports any of the formats mentioned before. If you have a npm package that contains folders for each project type, you can use the use shortcut.
npm i -g example-package
plz use example-package
# Shortcut for
plz config templates.react-app "$(npm root -g)/example-package/react-app"
plz config templates.react-component "$(npm root -g)/example-package/react-component"
plz config templates.module "$(npm root -g)/example-package/module"
info
right now that config is stored within the plz-cli in the node modules, so whenever your reinstall the package, the config will get lost … there's definitely a better solution/practise for that tho.
How do templates get parsed?
Templates get copied using copy-template-dir, which allows you to use placeholders via mustache template syntax. This way you get access to a lot of meta information that plz provides (see below).
All files of the template folder (or cloned repo) will be copied, please see the copy-template-dir library for more details or take a look at the default templates in templates/* 😊
Available variables
{
// Specified project name, in different casing variations
// for different use cases, e.g. dir/file names, class names, etc.
NAME: name,
SLUGGED_NAME: changeCase.paramCase(name),
TITLE_NAME: changeCase.titleCase(name),
CAMEL_CASE: changeCase.camelCase(name),
PASCAL_NAME: changeCase.pascalCase(name),
// To allow you naming it `{{PACKAGEJSON}}.json` in your package
// to not get npm etc confused!
PACKAGEJSON: 'package',
// React version specified in plz's peer dependencies for convenience
REACT_VERSION: pkg.peerDependencies.react,
// plz cli package name and current major version
// For convenience to add it to the templates package.json
CLI_NAME: pkg.name,
CLI_VERSION: cliVersion,
// Author and repo information retrieved via `git config --get *`
// For convenience again to add reasonable defaults to the package.json
HAS_AUTHOR_EMAIL: email ? ' ' : '',
AUTHOR_EMAIL: email ? `<${email}>` : '',
AUTHOR_NAME: username,
GIT_REMOTE_URL: remoteUrl,
// For convenience e.g. to be used in README.md template
YEAR: new Date().getFullYear()
}